import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class GridBagLayoutDemo extends Applet {
	GridBagLayout gbaglayout;

	GridBagConstraints constraints;

	public void init() {
		gbaglayout = new GridBagLayout();
		constraints = new GridBagConstraints();
		setLayout(gbaglayout);

		//Button 1
		Button btn1 = new Button("Button01");
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.gridwidth = 1;
		constraints.gridheight = 1;
		constraints.anchor = GridBagConstraints.CENTER;
		constraints.fill = GridBagConstraints.NONE;
		constraints.weightx = 0.0;
		constraints.weighty = 0.0;
		constraints.insets = new Insets(0, 0, 0, 0);
		constraints.ipadx = 0;
		constraints.ipady = 0;
		makeButton(gbaglayout, constraints, btn1);

		//Button 2
		Button btn2 = new Button("Button02");
		constraints.gridx = 1;
		makeButton(gbaglayout, constraints, btn2);

		//Button 3
		Button btn3 = new Button("Button03");
		constraints.gridx = 2;
		makeButton(gbaglayout, constraints, btn3);

		//Button 4
		Button btn4 = new Button("Button04");
		constraints.gridx = 3;
		makeButton(gbaglayout, constraints, btn4);

		//Button 5
		Button btn5 = new Button("Button05");
		constraints.gridx = 0;
		constraints.gridy = 1;
		constraints.gridwidth = 4;
		makeButton(gbaglayout, constraints, btn5);

		//Button 6
		Button btn6 = new Button("Button06");
		constraints.gridx = 0;
		constraints.gridy = 2;
		constraints.gridwidth = 3;
		makeButton(gbaglayout, constraints, btn6);

		//Button 7
		Button btn7 = new Button("Button07");
		constraints.gridx = 3;
		constraints.gridy = 2;
		constraints.gridwidth = 1;
		makeButton(gbaglayout, constraints, btn7);

		//Button 8
		Button btn8 = new Button("Button08");
		constraints.gridx = 0;
		constraints.gridy = 3;
		constraints.gridwidth = 1;
		constraints.gridheight = 2;
		makeButton(gbaglayout, constraints, btn8);

		//Button 9
		Button btn9 = new Button("Button09");
		constraints.gridx = 1;
		constraints.gridy = 3;
		constraints.gridwidth = 3;
		constraints.gridheight = 1;
		makeButton(gbaglayout, constraints, btn9);

		//Button 10
		Button btn10 = new Button("Button10");
		constraints.gridx = 1;
		constraints.gridy = 4;
		constraints.gridwidth = 3;
		constraints.gridheight = 1;
		makeButton(gbaglayout, constraints, btn10);
	}

	private void makeButton(GridBagLayout gbaglayout, GridBagConstraints constraints, Component component) {
		gbaglayout.setConstraints(component, constraints);
		add(component);
	}

	public static void main(String[] args) {
		Frame frame = new Frame("GridBagLayoutDemo");
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});

		GridBagLayoutDemo demo = new GridBagLayoutDemo();
		demo.init();

		frame.add(BorderLayout.CENTER, demo);
		frame.setSize(270, 150);
		//frame.setSize(361, 254);
		frame.setVisible(true);
	}
}
